<?php
namespace app\mapi\model;
use think\Model;

/**
 * 商品订单模型类
 * @author  黄明杰 vx:HMJ125855
 * @version 20190201
 */
class MallOrderModel extends Model
{

    protected $name = 'MallOrder';

    /**
     * 数据列表方法
     * @param   Array   $Where  查询条件
     * @param   String  $Field  查询字段
     * @param   Int     $Pages  分页页数
     * @param   Int     $Limit  每页条数
     * @param   Srting  $Order  查询排序
     * @return  Array
     */
    public function mList($Where = [], $Field = '*', $Pages = 0, $Limit = 10, $Order = 'order_id DESC'){
        $Where['order_del'] = 1;

        $Lists = $this->field($Field)->where($Where)->order($Order)->limit($Pages * $Limit, $Limit)->select();

        return ObjectToArray($Lists);
    }

    /**
     * 数据详情方法
     * @param   Array   $Where  查询条件
     * @param   String  $Field  查询字段
     * @return  Array
     */
    public function mInfo($Where = [], $Field = '*'){
        $Where['order_del'] = 1;

        $Infos = $this->field($Field)->where($Where)->find();

        return ObjectToArray($Infos);
    }

    /**
     * 数据详情方法
     * @param   Array   $Where  查询条件
     * @param   String  $Field  查询字段
     * @return  String
     */
    public function mField($Where, $Field){
        $Where['order_del'] = 1;

        return $this->where($Where)->value($Field);
    }

    /**
     * 数据新增方法
     * @param   Array   $Param  添加内容
     * @return  Array
     */
    public function mAdd($Param){
        $Code = 2;
        $Time = time();

        try{
            $Param['order_create'] = $Time;

            $Result = $this->allowField(true)->insert($Param);

            $AddID = $this->getLastInsID();

            if($Result){
                $Code = 1;
                $Msgs = lang('XtTsTjCg');
            }else{
                $Code = 2;
                $Msgs = lang('XtTsTjSb');
            }

            return ['code'=>$Code, 'msgs'=>$Msgs, 'urls'=>url('MallOrder/showList')];
        }catch(PDOException $e){
            return ['code'=>$Code, 'msgs'=>$e->getMessage()];
        }
    }

    /**
     * 数据更新方法
     * @param   Array   $Where  更新条件
     * @param   Array   $Param  更新内容
     * @return  Array
     */
    public function mEdit($Where, $Param){
        $Code = 2;
        $Time = time();

        try{
            $Where['order_del'] = 1;

            $Param['order_update'] = $Time;

            $Result = $this->allowField(true)->where($Where)->update($Param);

            if($Result){
                $Code = 1;
                $Msgs = '更新成功';
            }else{
                $Msgs = '更新失败';
            }

            return ['code'=>$Code, 'msgs'=>$Msgs];
        }catch(PDOException $e){
            return ['code'=>$Code, 'msgs'=>$e->getMessage()];
        }
    }

}